package com.sleepapp.utils;

import lombok.Data;

/**
 * @author ziluxike
 * @since 2025/5/26 10:32
 */
@Data
public class AjaxResult<T> {
    private int code;

    private String message;

    private T data;

    public AjaxResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> AjaxResult<T> success(T data) {
        return new AjaxResult<>(ResCode.SUCCESS.getCode(), ResCode.SUCCESS.getMessage(), data);
    }

    public static <T> AjaxResult<T> success() {
        return new AjaxResult<>(ResCode.SUCCESS.getCode(), ResCode.SUCCESS.getMessage(), null);
    }

    public static <T> AjaxResult<T> fail(ResCode resCode) {
        return new AjaxResult<>(resCode.getCode(), resCode.getMessage(), null);
    }

    public static <T> AjaxResult<T> fail(String message) {
        return new AjaxResult<>(ResCode.FAIL.getCode(), message, null);
    }

    public static <T> AjaxResult<T> fail() {
        return new AjaxResult<>(ResCode.FAIL.getCode(), ResCode.FAIL.getMessage(), null);
    }
}
